import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {Http, Headers, Response} from '@angular/http';
import {User} from '../model/user-model';
import {PostDetailService} from "../../post/post-detail/services/post-detail.service";
import {ActivatedRoute} from '@angular/router'

@Component({
  selector: 'app-user-info',
  templateUrl: './user-info.component.html',
  styleUrls: ['./user-info.component.scss']
})
export class UserInfoComponent implements OnInit {
  @Input()
  public panelTitle: string;


  @Output()
  public follow = new EventEmitter<string>();

  public postId: number;
  public userName: string;

  constructor(public http: Http,
              public postDetailService: PostDetailService,
              public activeRoute: ActivatedRoute) {
    //构造组件的时候，@Input的属性还没有值
    console.log(this.panelTitle);
  }


  ngOnInit() {
    console.log(this.panelTitle);
    this.activeRoute.params.subscribe(
      params => {
        this.postId = params['postId'];
        this.postDetailService
          .getPost(this.postId)
          .subscribe(
            data => this.userName = data.author,
            error => console.error(error)
          );
      }
    );
  }


  public followBtnClick() {
    this.follow.emit("follow");
  }
}
